/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sg.edu.nus.iss.pacman.util;

import java.util.Vector;
import sg.edu.nus.iss.pacman.dao.Score;
import sg.edu.nus.iss.pacman.dao.UserProfile;
import sg.edu.nus.iss.pacman.net.webservice.score;
import sg.edu.nus.iss.pacman.net.webservice.userProfile;

/**
 * Utility class for web services.
 * @author fredy
 */
public class WSUtils
{
    private WSUtils()
    {
    }

    /**
     * Convers the UserProfile to UserProfile web service format.
     * @param up the UserProfile
     * @return the UserProfile web service format
     */
    public static userProfile convertUserProfileToUserProfileWS(UserProfile up)
    {
        userProfile upWS = new userProfile();
        upWS.setName(up.getName());
        upWS.setEmail(up.getEmail());
        upWS.setGender(up.getGender());
        upWS.setDob(DateUtils.convertDateToString(up.getDob()));
        Vector scores = up.getScores();
        score[] scoresWS = new score[scores.size()];
        for (int i = 0; i < scores.size(); i++)
        {
            Score s = (Score) scores.elementAt(i);
            score sWS = new score();
            sWS.setMapName(s.getMapName());
            sWS.setScore(s.getScore());
            scoresWS[i] = sWS;
        }
        upWS.setScores(scoresWS);
        return upWS;
    }
}
